package com.ruoyi.ewem.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.ewem.domain.Firm;
import com.ruoyi.ewem.service.FirmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 加工工厂Controller
 *
 * @author ruoyi
 * @date 2024-07-27
 */
@RestController
@RequestMapping("/firm")
public class FirmController extends BaseController {
    @Autowired
    private FirmService firmService;

    /**
     * 查询加工工厂列表
     */
    @RequiresPermissions("ewem:firm:list")
    @GetMapping("/list")
    public TableDataInfo list(Firm firm) {
        startPage();
        List<Firm> list = firmService.selectFirmList(firm);
        return getDataTable(list);
    }

    /**
     * 导出加工工厂列表
     */
    @RequiresPermissions("ewem:firm:export")
    @Log(title = "加工工厂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Firm firm) {
        List<Firm> list = firmService.list();
        ExcelUtil<Firm> util = new ExcelUtil<Firm>(Firm.class);
        util.exportExcel(response, list, "加工工厂数据");
    }

    /**
     * 获取加工工厂详细信息
     */
    @RequiresPermissions("ewem:firm:query")
    @GetMapping(value = "/{firmId}")
    public AjaxResult getInfo(@PathVariable("firmId") Long firmId) {
        return success(firmService.getById(firmId));
    }

    /**
     * 新增加工工厂
     */
    @RequiresPermissions("ewem:firm:add")
    @Log(title = "加工工厂", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Firm firm) {
        return toAjax(firmService.save(firm));
    }

    /**
     * 修改加工工厂
     */
    @RequiresPermissions("ewem:firm:edit")
    @Log(title = "加工工厂", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Firm firm) {
        return toAjax(firmService.updateById(firm));
    }

    /**
     * 删除加工工厂
     */
    @RequiresPermissions("ewem:firm:remove")
    @Log(title = "加工工厂", businessType = BusinessType.DELETE)
    @DeleteMapping("/{firmIds}")
    public AjaxResult remove(@PathVariable Long[] firmIds) {
        return toAjax(firmService.removeBatchByIds(Arrays.asList(firmIds)));
    }
}
